<%-- 
    Document   : menu
    Created on : 22/05/2011, 04:09:52 PM
    Author     : Alex
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<jsp:useBean id="user" class="user.UserData" scope="session"/> 
<jsp:useBean id="userActual" class="user.UserData" scope="session"/> 
<jsp:useBean id="mapper" class="data.proyectoMapper" scope="application"/> 
<jsp:setProperty name="user" property="*"/>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Autenticando...</title>
    </head>
    <body>
      <%
        int tipo = mapper.autentificar(user.getUsername(),user.getPassword());
        if(tipo == 0) {
           userActual = mapper.copiar(user.getUsername());
           user.setEmail(userActual.getEmail());
           user.setTelefono(userActual.getTelefono());
           user.setId(userActual.getId());
           user.setTipo(tipo);
        %> <jsp:forward page="menu.jsp"/> <% 
        }else if(tipo > 0){ 
           userActual = mapper.copiar(user.getUsername());
           user.setEmail(userActual.getEmail());
           user.setTelefono(userActual.getTelefono());
           user.setId(userActual.getId());
           user.setTipo(tipo);
        %> <jsp:forward page="menu.jsp"/> <% 
        }else{
           user.setUsername("");
           user.setPassword("");
        %> <jsp:forward page="loginFail.jsp"/> <% } %>
    </body>
</html>
